import React from 'react'
import { Route, Switch } from 'react-router-dom'


function renderRoutes(routes, extraProps = {}, switchProps = {}) {
    // window.mapOnload = false;
    return routes ? (
        <Switch {...switchProps}>
            {routes.map((route, i) => (
                <Route
                    key={route.key || i}
                    path={route.path}
                    exact={route.exact}
                    strict={route.strict}
                    render={(props) => (route.render ? (
                        route.render({ ...props, ...extraProps, route })
                    ) : (
                        <>
                            {
                                route.component && <route.component {...props} {...extraProps} route={route} >
                                    {
                                        route.routes && renderRoutes(route.routes, extraProps) 
                                    }
                                </route.component>
                            }
                        </>
                    ))}
                >
                </Route>
            ))}
        </Switch>
    ) : null;
}

export default renderRoutes